package demo1;

class Solution {
    public ListNode removeDuplicateNodes(ListNode head) {
       ListNode cur = head ;
       while(cur != null){
          ListNode curNext = cur.next ;
          if(searchFront(head ,curNext)){
              remove(cur) ;
          }
          cur = cur.next ;
       }
       return head ;

    }
    public boolean searchFront(ListNode head , ListNode cur){
       if(cur == null) return false;
       
       ListNode ret = head ;
       while(ret!=cur ){
             if(ret.val == cur.val){
                 return true ;
             }
             ret = ret.next ;
       }
       return false ;
    }

    public void remove(ListNode cur){
       if(cur == null && cur.next == null){
           return ;
       }
       cur.next = cur.next.next ;

    }

}